package com.dgut.controller;

import com.dgut.entity.Record;
import com.dgut.service.RecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class UserController {

    @Resource
    RecordService recordService;

    @PostMapping("/handInfo")
    public String handInfo(@RequestBody Record record) {
        // 判断可以插入
        log.info("收到的record{}", record);
        Record existRecord = recordService.getRecordByStuIdAndDate(record.getStu_id(), record.getDate());
        log.info("数据库找到的record{}", record);
        if (existRecord == null) {
            try {
                recordService.insertRecord(record);
                return "打卡成功";
            } catch (Exception e) {
                e.printStackTrace();
                return "打卡发生错误";
            }
        } else {
            return "该学生今日已打卡，请勿重复提交";
        }
    }
}
